package com.kai.auth.data;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 登录用户信息
 * </p>
 *
 * @author weijk
 * @since 2023/6/29
 */
@Data
@Accessors(chain = true)
public class LoginUser implements UserDetails, CredentialsContainer {

    private static final long serialVersionUID = 5045786279664854772L;

    private Long userId;

    private String username;

    private String password;

    private List<GrantedAuthority> authorities;

    private LocalDateTime expirationTime;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public void eraseCredentials() {
        this.password = null;
    }
}

